//
//  TravelNotesSecondTableViewCell.m
//  ITrip
//
//  Created by dlios on 15-5-22.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TravelNotesSecondTableViewCell.h"
#import "UIImageView+AFNetworking.h"
@implementation TravelNotesSecondTableViewCell

- (void)dealloc
{
    [_day release];
    [_name_zh_cn release];
    [_entry_name release];
    [_descrip release];
    [_titleView release];
    [_url release];
    [_comment release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
        
        
        
        
        
//        UIVisualEffectView
    }
    return self;
}

- (void)createCell
{
    self.titleView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleView];
     self.name_zh_cn = [[UILabel alloc] init];
    [self.contentView addSubview:self.name_zh_cn];
    self.url = [[UIImageView alloc] init];
    [self.contentView addSubview:self.url];
    self.descrip = [[UILabel alloc] init];
    [self.contentView addSubview:self.descrip];
    self.comment = [[UILabel alloc] init];
    [self.contentView addSubview:self.comment];
    self.contentView.backgroundColor = [UIColor colorWithRed:231 / 255.0 green:237 / 255.0 blue:241 / 255.0 alpha:1];
    [self.titleView release];
    [self.name_zh_cn release];
    [self.url release];
    [self.descrip release];
    
}


- (void)setTravelNotesSecondModel:(TravelNotesSecondModel *)travelNotesSecondModel
{
//    NSLog(@"1");
//    _travelNotesSecondModel = travelNotesSecondModel;
    if (travelNotesSecondModel.entry_type != nil && ![travelNotesSecondModel.entry_type isEqual:[NSNull null]]) {
        
        self.titleView.frame = CGRectMake(15, 10, 30, 30);
        self.titleView.backgroundColor = [UIColor whiteColor];
        self.titleView.layer.borderColor = [UIColor grayColor].CGColor;
        self.titleView.backgroundColor = [UIColor clearColor];
//        self.titleView.layer.cornerRadius = 20;
//        self.titleView.layer.masksToBounds = YES;
        self.titleView.image = [UIImage imageNamed:@"iconfont-dingwei"];
        self.name_zh_cn.frame = CGRectMake(60, 15, 200, 25);
        self.name_zh_cn.text = travelNotesSecondModel.entry_name;
    }
    
   [self.url setImageWithURL:[NSURL URLWithString:travelNotesSecondModel.url] placeholderImage:nil];
    
    // 有title
    if (travelNotesSecondModel.entry_type != nil && ![travelNotesSecondModel.entry_type isEqual:[NSNull null]]) {
        // 有图片
        if (travelNotesSecondModel.url != nil && ![travelNotesSecondModel.url isEqual:[NSNull null]]) {
            self.url.frame = CGRectMake(10, 60, self.frame.size.width - 20, (self.frame.size.width - 20) * (travelNotesSecondModel.image_height / (CGFloat)travelNotesSecondModel.image_width));
             [self.url setImageWithURL:[NSURL URLWithString:travelNotesSecondModel.url] placeholderImage:[UIImage imageNamed:@"defaultPicture"]];

            if (travelNotesSecondModel.descrip != nil && ![travelNotesSecondModel.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, (self.url.frame.origin.y + (self.frame.size.width - 20) * (travelNotesSecondModel.image_height / (CGFloat)travelNotesSecondModel.image_width) + 10), self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesSecondModel.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];

            }
            
        } else {
            if (travelNotesSecondModel.descrip != nil && ![travelNotesSecondModel.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, 60, self.frame.size.width - 20, 30);
                
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesSecondModel.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];

            }
            
        }
        
        
    } else if (travelNotesSecondModel.entry_type == nil || [travelNotesSecondModel.entry_type isEqual:[NSNull null]]) { // 无title
        // 有图
        if (travelNotesSecondModel.url != nil && ![travelNotesSecondModel.url isEqual:[NSNull null]]) {
            self.url.frame = CGRectMake(10, 10, self.frame.size.width - 20, (self.frame.size.width - 20) * (travelNotesSecondModel.image_height / (CGFloat)travelNotesSecondModel.image_width));
             [self.url setImageWithURL:[NSURL URLWithString:travelNotesSecondModel.url] placeholderImage:[UIImage imageNamed:@"defaultPicture"]];
            
            if (travelNotesSecondModel.descrip != nil && ![travelNotesSecondModel.descrip isEqual:[NSNull null]]) {
                
                self.descrip.frame = CGRectMake(10, self.url.frame.origin.y + (self.frame.size.width - 20) * (travelNotesSecondModel.image_height / (CGFloat)travelNotesSecondModel.image_width) + 10, self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesSecondModel.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];

   
            }
            
        } else {
            // 无图
            if (travelNotesSecondModel.descrip != nil && ![travelNotesSecondModel.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, 10, self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesSecondModel.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];

            }
        }
    }
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
